package test;

import pojo.Student;
import util.JDBCUtils;

import java.sql.Connection;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class Main {


    public static void main(String [] args) {
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        Connection conn=null;


        try{
            Connection Conn= JDBCUtils.getConnection();
           preparedStatement= Conn.prepareStatement("select *from student where sno=?");
            preparedStatement.setString(1,"202010804001");
            resultSet=preparedStatement.executeQuery();
            System.out.println("连接数据库成功！");
            List<Student> list = new ArrayList<>();
            while (resultSet.next()){
                String sno=resultSet.getString(1);
                String sname=resultSet.getString(2);
                String sex=resultSet.getString(3);
                int grade=resultSet.getInt(4);
                Student student = new Student(sno,sname,sex,grade);
                list.add(student);
            }
            System.out.println(list);
        }catch(Exception e)
        {
            e.printStackTrace();
            System.out.print("SQL Server连接失败！");
        }
            JDBCUtils.close(conn);

    }


}
